Demo: Comboboxes and Hot Keys

© 2006, Bill Jennings

author contact:

bbjen@hotPOP.com

NL42 Home

::::::::::::::::::::::::::::::::::::::::::::::::::::

API Corner

Technical Writing

Eddie V11

Sub Event Handlers

Comboboxes / Hot Keys

Wire - Reminders / Tips

::::::::::::::::::::::::::::::::::::::::::::::::::::

Submission Guildlines

Newsletter Help

Index


Bill Jennings submitted a demo that uses an API call to force the selection of a control, rather than the handle of the control, to be passed to the sub event handler. In Bill's words

I'm a hot key addict, having learned the business before mice and windows, so I can't resist bypassing the mouse whenever I can (for speed). This combobox demo permits scrolling with the up or down arrow keys and selection with the Enter key. It does not use any hidden button, and thus does not require a dialog window. What I have coded works, but things might get complicated if more controls were added to the scan loop - Bill J.


'Demo permits arrow keys scrolling of combobox
  'with selection by pressing Enter key.

    WindowWidth = 400
    WindowHeight = 500
    UpperLeftX = Int((DisplayWidth - WindowWidth)/2)
    UpperLeftY = Int((DisplayHeight - WindowHeight)/3)

    Dim month$(12)
    For i = 1 to 12
        Read m$
        month$(i) = m$
    Next i

        nomainwin

    Combobox #main.cb1, month$(), selMonth, 50, 80, 100, 124
    Stylebits #main.cb1, _CBS_DROPDOWNLIST, 0, 0, 0  'inhibits mouse selection

  open "" for window_nf as #main
    #main, "trapclose [quit]"
    hndCB=hwnd(#main.cb1)  'handle of combobox
    Call DropDown hndCB
    #main.cb1, "setfocus"

    buffer$=space$(256)+chr$(0)  'buffer$ is used in [scanLoop].

      '*** pause to clear buffer
    calldll #kernel32,"Sleep",200 as ulong,r as void

[scanLoop]
  SCAN
    Esc=0 : Ent=0  'reset flags
      calldll #user32, "GetKeyboardState",_
        buffer$ as ptr, result as void

'*** Look for keypress of the Enter key
'***   14 is the decimal Virtual Key code + 1
    Ent$=mid$(buffer$,14)
    if asc(Ent$)>127 then Ent=1

      '*** ms delay to save processor cycles:
    calldll #kernel32,"Sleep",1 as ulong,r as void

  if Ent then
    #main.cb1, "Contents? sel$"

    if sel$>"" then Call selMonth sel$

      '*** pause to clear buffer
    calldll #kernel32,"Sleep",200 as ulong,r as void
  end if
  goto [scanLoop]

[quit]
  close #main
  END

    Data "January", "February", "March", "April", "May", "June", "July"
    Data "August", "September", "October", "November", "December"
'-----------------------------------
Sub DropDown hCombobox
  CallDLL #user32, "SendMessageA",_
    hCombobox as long,_
    _CB_SHOWDROPDOWN as long,_
    1 as long, 0 as long, r as void
End Sub

Sub selMonth sel$
        Notice chr$(13)+"You chose ";sel$+chr$(13)
        #main.cb1, "Reload"
End Sub

There are always more ways to approach and solve a problem. Thanks for submitting, Bill!


NL42 Home

::::::::::::::::::::::::::::::::::::::::::::::::::::

API Corner

Technical Writing

Eddie V11

Sub Event Handlers

Comboboxes / Hot Keys

Wire - Reminders / Tips

::::::::::::::::::::::::::::::::::::::::::::::::::::

Submission Guildlines

Newsletter Help

Index